import { IMessageObj } from "./message";
import axios from "./request";
import { IErrorData, ISuccessPageData } from "./returnData";

export interface ICommentObj extends IMessageObj {
    blog: {
        title: string,
        id: string
    }
}

export interface ICommentQuery {
    page: number,
    limit: number,
    blogid?: string,
    keyword?: string
}

export interface IReturnCom {
    total: number,
    rows: ICommentObj[]
}

/**
 * 分页获取评论
 * @param query 条件
 * @returns 
 */
export function getPageComment(query: ICommentQuery = { page: 1, limit: 10, blogid: "-1" }): Promise<ISuccessPageData<IReturnCom> | IErrorData> {
    console.log(query)
    return axios.get('/api/comment', {
        params: query
    });
}

/**
 * 
 * @param id 文章评论id值
 * @returns 
 */
export function deleteComment(id: string): Promise<ISuccessPageData<boolean> | IErrorData> {
    return axios.delete(`/api/comment/${id}`);
}